/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 小梅就是酱子
 * Date: 2022-01-26
 * Time: 20:10
 */
public class 青蛙跳台阶问题 {

    //递归方法
    public static int frog(int n){
        if(n==1 || n==2){
            return n;
        }
        return frog(n-1)+frog(n-2);
    }

    //非递归的方法(循环)
    public static int frog2(int n){
        if(n==1 || n==2){
            return n;
        }
        int c1=1;
        int c2=2;
        int c3=0;

        for(int i=3;i<=n;i++){
            c3=c1+c2;
            c1=c2;
            c2=c3;
        }
        return c3;
    }
    public static void main(String[] args) {
        System.out.println(frog(4));
        System.out.println(frog2(4));

    }
}
